package reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class reflectDemo4 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.dance();


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要实例化的类的类名：");
        String classname = scanner.nextLine();
        System.out.println("请输入要实例化的方法对象：");
        String methodname = scanner.nextLine();
        Class cls = Class.forName(classname);
        Object obj = cls.newInstance();
        Method method = cls.getMethod( methodname);
        method.invoke(obj);

    }
}
